Smartface 4.5 crashes with Create Table - smartface.io

Smartface 4.5 crashes on Android without any error code if you try to create table with following code.
How to create local table with this new version?
Data.execute("DROP TABLE IF EXISTS testtable;");
Data.execute("Create table testtable (col1 int, col2 int)");

This is a known issue, it will be fixed.
450 will be updated soon.

Related

PostgreSQL 10 partition by list using enums

I am trying to partition my table using enum column and I am encountering a somewhat strange behaviour.
create type positivity as enum (
'POSITIVE',
'NEGATIVE'
);
create table test (id int, polarity positivity) partition by list (polarity);
create table test_1 partition of test for values in ('POSITIVE');
create table test_2 partition of test for values in ('NEGATIVE');
explain select * from test where polarity = 'NEGATIVE';
For this code this is what I get for output of explain:
My question is why is it working like that and is this a bug or a feature in postgres?
EDIT: Adding constraints manually improves the query plan and that way I've got what I wanted (but I am still wandering about the behaviour explained above):
alter table test_1 add constraint test_1_check check(polarity='POSITIVE');
alter table test_2 add constraint test_1_check check(polarity='NEGATIVE');
New query plan for the same explain command:
For anyone looking at this in mid 2018, the fix hasn't made it into release yet; I'm still seeing it happen on 10.4.
Here's the commit for the fix, which appears it is being reviewed this month -
https://commitfest.postgresql.org/17/1591/

PostgreSQL syntax error related to INSERT and/or WITH. Occurs in 8.4 but not 9.1. Ideas?

Here is some SQL for PostgreSQL (I know it's a silly query; I've boiled the original query down to the simplest broken code):
CREATE TABLE entity (
id SERIAL PRIMARY KEY
);
WITH new_entity
AS (INSERT INTO entity DEFAULT VALUES
RETURNING id
)
SELECT id FROM new_entity;
Here it is running on PostgreSQL 9.1:
psql:../sandbox/test.sql:3: NOTICE: CREATE TABLE will create implicit sequence "entity_id_seq" for serial column "entity.id"
psql:../sandbox/test.sql:3: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "entity_pkey" for table "entity"
CREATE TABLE
id
----
1
(1 row)
Here it is not running on PostgreSQL 8.4:
psql:../sandbox/test.sql:3: NOTICE: CREATE TABLE will create implicit sequence "entity_id_seq" for serial column "entity.id"
psql:../sandbox/test.sql:3: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "entity_pkey" for table "entity"
CREATE TABLE
psql:../sandbox/test.sql:9: ERROR: syntax error at or near "INSERT"
LINE 2: AS (INSERT INTO entity DEFAULT VALUES
Obviously, the table creation goes fine in both cases, but it wipes out on the second query in PostgreSQL 8.4. From this error message I am unable to gather exactly what the problem is. I don't know what it is that 9.1 has and 8.4 doesn't have that could result in this syntax error. It's hilariously hard to google it. I am approaching the level of desperation required to trawl through the pages of PostgreSQL release notes between 8.4 and 9.1 and finding out if anything related to WITH … AS or INSERT … RETURNING was changed or added, but before I go there I am hoping one of you has the experience and/or godly google-fu to help me out here.
Data-modifying statements in WITH were introduced in Postgres 9.1

Cannot update view in PostgreSQL?

My site was developed using Drupal 6 running on a Postgresql 8.3 server on Ubuntu 11.10. Also webmin version 1.590.
Now I want to update records in a table, but when I run:
UPDATE uac_institution_view SET status = '2' WHERE nid = '9950'
it gives me an error like:
Failed to execute SQL : SQL UPDATE uac_institution_view SET status =
'2' WHERE nid = '9950' failed : ERROR: cannot update a view HINT: You
need an unconditional ON UPDATE DO INSTEAD rule.
The problem is that only SELECT queries work. UPDATE, INSERT and DELETE commands are not working; they fail with the above error.
Is this a permisssion problem? A syntax error? Something else?
PostgreSQL views are not updateable by default. You must tell PostgreSQL how you want the view to be updated.
Do this using "an unconditional ON UPDATE DO INSTEAD rule" (as the error message you pasted said) or preferably on PostgreSQL 9.1 and above using a view trigger. I provided links to all that in my answer to your previous post, but here's some more info:
updateable views in PostgreSQL 9.1 using INSTEAD OF trigger
updateable views (for Pg 9.0 and below using rules)
CREATE TRIGGER
CREATE VIEW
rules vs triggers
rules
triggers in PL/pgSQL
In many cases it's better to leave the view read-only and just update the underlying table. Since you have not provided a definition of the view it's hard to say what that would actually involve. Update your question with the output of running \d uac_institution_view in psql and comment to say you've done so; maybe I can point out a way to run the update directly on the underlying table(s).
You are using a very obsolete version of PostgreSQL (8.3) so you cannot use the preferred INSTEAD OF trigger approach, you must either use rules or update the underlying table directly.
FYI, after the answer involving rules/triggers was posted, PostgreSQL 9.3 came out with auto-updatable views. Version 9.3 is in beta 2 as of June 27, 2013, so it's not yet GA.
Here is an example: https://web.archive.org/web/20160322164044/http://michael.otacoo.com/postgresql-2/postgres-9-3-feature-highlight-auto-updatable-views/
I am on postgres 9.5 and views are updatable by default.
Example :
CREATE TABLE UP_DATE (id number, name varchar2(29));
insert into up_date values(1, 'Foo');
select * from up_date;
CREATE OR REPLACE VIEW UPDATE
AS
Select
name from up_date;
select * from update;
insert into update values('Bar');
select * from update;
Will out put Foo and Bar
Everything just works from PG 9.3 onwards as noted by Jeff French... With some exceptions (more info below).
Simple example
You can test this code on your PostgreSQL. Use cascade drop when you are done (to drop view with the table).
-- create table
--DROP TABLE user_table CASCADE;
CREATE TABLE user_table (
id serial,
lastname varchar(100),
user_type varchar(2) DEFAULT 'nn',
PRIMARY KEY (id)
);
-- initial data
INSERT INTO user_table(lastname) VALUES('Foo');
SELECT * FROM user_table;
-- simple view (note, no id here)
CREATE OR REPLACE VIEW user_view
AS
SELECT lastname, user_type
FROM user_table
;
-- check view (will have initial data)
SELECT * FROM user_view;
-- insert into user_table via view
INSERT INTO user_view VALUES('Bar');
-- check (both will have both records)
SELECT * FROM user_view;
SELECT * FROM user_table;
-- you can run above many times
-- (id will auto-increment even though it is not in the view)
-- update user_table via view
UPDATE user_view SET user_type='v' WHERE lastname = 'Bar';
SELECT * FROM user_table;
Limitations
There are some limitations though and that will depend on you PG version.
In PG 9.3 views cannot have any expressions etc. Also only one table is allowed... So more or less a simple select limiting, reordering, or renaming columns.
In PG 9.4 views can be partially updatable. So you can have expression but you will not be able to update them (not out of the box at least).
If you have WHERE in your view then you might get a bit weird results. So this will still work with insert:
CREATE OR REPLACE VIEW user_view
AS
SELECT lastname as last_name, user_type
FROM user_table
WHERE user_type = 'v'
;
INSERT INTO user_view VALUES('Bar');
But update might not work. At least this will not work in that it will update 0 rows:
UPDATE user_view SET user_type='v';
Because effectively that would be equivalent to below query (so makes sense if you think about it):
UPDATE user_view SET user_type='v' WHERE user_type = 'v';
I wonder if at some point they might support joins... But at the time of writing PG 14 is out and it doesn't support joined tabled in views (for updates I mean).
Alternatives
You can still use INSTEAD OF triggers, especially for more complicated views. And you can use rules... But (as noted in the CREATE RULE docs) automatically updatable views will be faster then manually created rules.

Mysterious disappearance of an Index in an Oracle 10g table

I have a table in an Oracle database. An Index has mysteriously disappeared. Is there any way to find out how that happened? I am using Toad for Oracle Version 9.5.0.31
Thanks
I'm not sure you can find out after the fact but you can log future DROPs"
CREATE or replace TRIGGER your_name AFTER DROP
ON your_schema
pl/sql_block
You'll also have to create a logging table and insert into it.

ID numbers generation

i am trying to code for my system in NetBeans IDE 6.5 to auto generate ID numbers for me like autonumbers in Ms Access. does any one have any ideas about going about that?i mean code for it.
What database system are you using? If it's something SQL based:
CREATE TABLE $tblname (id int(10) NOT NULL auto_increment PRIMARY KEY (id))
Try using auto_increment , such as in the example above.
If you're using JavaDB you need the GENERATED AS IDENTITY option on a field in your CREATE TABLE statement.
In the Windows API you can create a Guid. I'm sure there is some similar UID API for Netbeans.
If you're using Oracle, you will need a sequence for each table.
once you have the sequence you can create a trigger like this:
Create or Replace trigger incrementOnInsert
before insert on TABLE
for each row
begin
select sequence.nextval into :new.id from dual;
end;