Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating view malforms database #4982

Open
mohmad-null opened this issue May 5, 2024 · 0 comments
Open

Creating view malforms database #4982

mohmad-null opened this issue May 5, 2024 · 0 comments

Comments

@mohmad-null
Copy link

3.4.4, 3.3.3, even 2.1.5

Create a database:

CREATE TABLE urls (
	url_id			INTEGER		PRIMARY KEY		AUTOINCREMENT,
	url				TEXT	 	UNIQUE						NOT NULL
);

CREATE TABLE lookups (
	lookup_id		  	INTEGER  	PRIMARY KEY AUTOINCREMENT,
	url_id			 	INTEGER 	REFERENCES urls (url_id) ON DELETE CASCADE		NOT NULL,
	content_hash	   	TEXT	 	COLLATE NOCASE,
	retrieval_datetime 	DATETIME	DEFAULT (datetime('now'))
);

CREATE VIEW v_most_recent_lookup_per_url AS
	SELECT url_id,
		   MAX(retrieval_datetime) AS retrieval_datetime
	  FROM lookups
	 GROUP BY url_id;
	 

All runs fine.

Now run this, replacing "db2" with whatever the schema alias is:

CREATE VIEW db2.v_latest_content_hash_for_url AS
	SELECT
		url,
		content_hash
	FROM
		db2.lookups l
	JOIN
		(SELECT
			*
		FROM
			db2.v_most_recent_lookup_per_url
		) sub
		ON l.url_id = sub.url_id and l.retrieval_datetime = sub.url_id
	JOIN
		db2.urls USING (url_id)

SQLite studio will now drop the entire database and be unable to re-open it, as it's now "malformed".

The problem is the schema part of CREATE VIEW [schema].v_latest_content_hash_for_url - if you leave it empty SQLite will refuse to run it. If you add a schema, it'll break.

The same create-view query runs just fine via Python, but then SQLiteStudio can't open the file ("malformed").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant