CodeIgniter Forums
Type casting in PostgreSQL with updateBatch() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Type casting in PostgreSQL with updateBatch() (/showthread.php?tid=88871)

Pages: 1 2 3


RE: Type casting in PostgreSQL with updateBatch() - kenjis - 01-16-2024

I sent a PR: https://github.com/codeigniter4/CodeIgniter4/pull/8426


RE: Type casting in PostgreSQL with updateBatch() - MrWhite - 01-16-2024

(01-16-2024, 09:27 PM)kenjis Wrote: I sent a PR: https://github.com/codeigniter4/CodeIgniter4/pull/8426

Man I couldn't be any more happier. Thank you so-much. You made my day.
You are the best. Love you ma man. (y)


RE: Type casting in PostgreSQL with updateBatch() - kenjis - 01-16-2024

Tests and reviews are welcome.


RE: Type casting in PostgreSQL with updateBatch() - MrWhite - 01-17-2024

I hope individuals with strong technical skills can offer assistance. I wish I possessed such skills to contribute. I attempted to rectify this after a few hours of struggling, but unfortunately, I failed. Every value is gets enclosed in quotes. I spent several days trying to comprehend how things interconnect, but I couldn't figure it out.

I want to convey that I genuinely desire to actively contribute to CI4, but I'm not at that level yet. I highly appreciate what you all are doing here. I eat, live, and take care of my family because of you guys. Thank you so much Smile


RE: Type casting in PostgreSQL with updateBatch() - byrallier - 01-17-2024

(01-01-2024, 01:19 PM)MrWhite Wrote: I have this issue. i dunno what to do. Sad

my whole project is now stuck at this point. cant go forward without having a solution to this. i nerver had this type of issue in ci3.

i suggest this kind of way casting types, $builder->updateBatch($data, ['title', 'author', 'data:jsonb']);

(01-16-2024, 09:48 PM)kenjis Wrote: Tests and reviews are welcome.

I reviewed its fine but it has to be documented. I will give it a try on its test


RE: Type casting in PostgreSQL with updateBatch() - kenjis - 01-17-2024

Added the docs: https://github.com/codeigniter4/CodeIgniter4/pull/8426


RE: Type casting in PostgreSQL with updateBatch() - sclubricants - 01-19-2024

The quick and easy fix for this is to use RawSql as well as casting your php values:
Code:
$data = [
                [
                    'name'                  => 'Derek Jones',
                    'savings'               => (float) '28389.48',
                    'updated_at' => new RawSql("'2023-12-02 18:47:52'::TIMESTAMP"),
                ],
            ];

https://codeigniter.com/user_guide/database/query_builder.html#rawsql

Another things to have a look at is:

https://www.postgresql.org/docs/current/sql-createcast.html


RE: Type casting in PostgreSQL with updateBatch() - MrWhite - 01-19-2024

(01-17-2024, 08:19 PM)kenjis Wrote: Added the docs: https://github.com/codeigniter4/CodeIgniter4/pull/8426
Big thanks   Heart
(01-19-2024, 03:25 PM)sclubricants Wrote: The quick and easy fix for this is to use RawSql as well as casting your php values:
Code:
            $data = [
                [
                    'name'                  => 'Derek Jones',
                    'savings'              => (float) '28389.48',
                    'updated_at' => new RawSql("'2023-12-02 18:47:52'::TIMESTAMP"),
                ],
            ];

https://codeigniter.com/user_guide/database/query_builder.html#rawsql

Another things to have a look at is:

https://www.postgresql.org/docs/current/sql-createcast.html

Yeah! nice trick.


RE: Type casting in PostgreSQL with updateBatch() - kenjis - 01-20-2024

There are four options now. Any opinion? or another solution?
See https://github.com/codeigniter4/CodeIgniter4/pull/8426#issuecomment-1901901019


RE: Type casting in PostgreSQL with updateBatch() - kenjis - 01-20-2024

I sent another PR. This seems better.

fix: [Postgre] QueryBuilder::updateBatch() does not work (No API change) by kenjis · Pull Request #8439 · codeigniter4/CodeIgniter4
https://github.com/codeigniter4/CodeIgniter4/pull/8439